package com.wzy.netty.nio;

import lombok.extern.slf4j.Slf4j;

import java.nio.ByteBuffer;

/**
 * 描述  : 注意 put 和 get 数据的类型匹配
 * 创建人:    Wzy
 * 创建时间: 2020-06-10  15:02
 */
@Slf4j
public class NIOByteBufferPutGet {
    public static void main(String[] args) {
        ByteBuffer byteBuffer = ByteBuffer.allocate(64);
        byteBuffer.putInt(199);
        byteBuffer.putLong(2222222);
        byteBuffer.putChar('好');
        byteBuffer.putShort((short) 4);

        //取出,顺序必须保证和放入的顺序保持一致，否则报错
        byteBuffer.flip();
        log.info(String.valueOf(byteBuffer.getInt()));
        log.info(String.valueOf(byteBuffer.getLong()));
        log.info(String.valueOf(byteBuffer.getChar()));
        log.info(String.valueOf(byteBuffer.getShort()));
    }
}
